<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return redirect('/posts');
});

// http 方法
/*Route::match(['get', 'post'], function () {

});*/

// 路由参数
/*Route::get('/posts/{id}', function ($id) {
    return $id;
});*/

// 路由分组
/*Route::group(['prefix' => '/posts'], function (){

});*/

// 模型绑定
/*Route::get('/posts/{post}', function (Post $post) {
    return $post;
});*/


// 文章模块

Route::group([
    'where' => ['post' => "\d+"],
    'prefix' => '/posts',
], function () {
    // 创建文章
    Route::get("/create", "\\App\\Http\\Controllers\\PostController@create");
    Route::post("/", "\\App\\Http\\Controllers\\PostController@store");

    // 文章列表
    Route::get("/", "\\App\\Http\\Controllers\\PostController@index");

    // 文章详情
    Route::get("/{post}", "\\App\\Http\\Controllers\\PostController@show");

    // 编辑文章
    Route::get("/edit/{post}", "\\App\\Http\\Controllers\\PostController@edit");
    Route::put("/{post}", "\\App\\Http\\Controllers\\PostController@update");

    // 删除文章
    Route::get('/delete/{post}', "\\App\\Http\\Controllers\\PostController@delete");

    // 提交评论
    Route::post('/comments/{post}', "\\App\\Http\\Controllers\\PostController@comment");

    // 提交赞
    Route::get('/zan/{post}', "\\App\\Http\\Controllers\\PostController@zan");
    // 取消赞
    Route::get('/unzan/{post}', "\\App\\Http\\Controllers\\PostController@unzan");

    // 搜索列表页
    Route::get('/search', "\\App\\Http\\Controllers\\PostController@search");

    Route::post('/image/upload', "\\App\Http\\Controllers\\PostController@imageUpload");
});

Route::get('/note', "\\App\Http\\Controllers\\PostController@note");

// 图片上传



// 用户个人中心

Route::group([
    'prefix' => '/user',
    'where' => ['user' => '\d+'],
], function () {
    // 注册页面
    Route::get('/register', "\\App\Http\\Controllers\\Users\\RegisterController@index");
    // 注册行为
    Route::post('/register', "\\App\Http\\Controllers\\Users\\RegisterController@register");

    // 登录页面
    Route::get('/login', "\\App\Http\\Controllers\\Users\\LoginController@index");
    // 登录行为
    Route::post('/login', "\\App\Http\\Controllers\\Users\\LoginController@login");
    // 登出行为
    Route::get('/logout', "\\App\Http\\Controllers\\Users\\LoginController@logout");

    // 个人设置页面
    Route::get('/setting', "\\App\Http\\Controllers\\Users\\UserController@setting");
    // 个人设置页面
    Route::post('/setting', "\\App\Http\\Controllers\\Users\\UserController@settingStore");

    // 个人中心
    Route::get('/{user}', "\\App\Http\\Controllers\\Users\\UserController@show");
    // 关注
    Route::post('/{user}/fan', "\\App\Http\\Controllers\\Users\\UserController@fan");
    // 取消关注
    Route::post('/{user}/unfan', "\\App\Http\\Controllers\\Users\\UserController@unfan");
});

// 专题
Route::group([
    'prefix' => '/topic',
    'where' => ['topic' => '\d+'],
], function () {
    // 专题详情
    Route::get('/{topic}', "\\App\\Http\\Controllers\\TopicController@show");
    // 投稿
    Route::post('/{topic}/submit', "\\App\Http\\Controllers\\TopicController@submit");

});

// 通知
Route::get('/notices', "\\App\Http\\Controllers\\NoticeController@index");

// 后台管理
Route::group([
    'prefix' => '/admin',
], function () {

    include_once 'admin.php';

});

Route::get('/404', function () {
    return view('/404');
});

Route::group([], function () {
    return redirect('/404');
});
